﻿using System;
using com.huigo.Framework.BLL;
using System.Collections.Generic;
using System.Web.Security;
namespace com.huigo.Framework.Service
{
    public partial class ServiceClass
    {
        public int Source = 0;

        public string DoUserLogin(string userName, string password, string ip)
        {
            string md5Pwd = null;
            md5Pwd = new com.loto.Common.ASPMD5().MD5(password);
            try
            {
                Model.UserInfo userInfo = new Model.UserInfo();

                userInfo = BLL.UserInfo.GetUserInfoByLoginNameAndPwd(userName, md5Pwd);

                if (userInfo == null) return string.Empty;

                Response<Model.UserInfo> el = new Response<Model.UserInfo>();
                el.Status = "SUC";
                el.Result = userInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "DoLogin(" + userName + ", " + password + ", " + ip + ") error:" + ex.Message);
                return string.Empty;
            }
        }
        //前台用户登录
        public string DoCustLogin(string userName, string password, string ip)
        {
            string md5Pwd = null;
            md5Pwd = new com.loto.Common.ASPMD5().MD5(password);
            try
            {
                Model.CustInfo custInfo = new com.huigo.Framework.Model.CustInfo();
                if (com.loto.Common.Utils.IsEmail(userName))
                {
                    custInfo = BLL.CustInfo.GetCustInfoByCustEmailAndPwd(userName, md5Pwd);
                }
                else
                {
                    custInfo = BLL.CustInfo.GetCustInfoByCustIdAndPwd(userName, md5Pwd);
                }

                if (custInfo == null) return string.Empty;

                Response<Model.CustInfo> el = new Response<com.huigo.Framework.Model.CustInfo>();
                el.Status = "SUC";
                el.Result = custInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "DoCustLogin(" + userName + ", " + password + ", " + ip + ") error:" + ex.Message);
                return string.Empty;
            }
        }
        /// <summary>
        /// 前台用户登录成功日志
        /// </summary>
        /// <param name="type"></param>
        /// <param name="custFid"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public string LoginLog(byte type, long custFid, string ip)
        {
            try
            {
                int result = BLL.LoginLog.InsertLoginLog(type, custFid, ip);
                if (result > 0)
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "LoginLog(" + type + ", " + custFid + ", " + ip + ") error:" + ex.Message);
                return string.Empty;
            }
        }
        //后台添加登录日志
        public string updateUserInfoLastTime(long userID)
        {
            try
            {
                bool result = BLL.UserInfo.updateUserInfoLastTime(userID);
                if (result)
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "updateUserInfoLastTime(" + userID + ") error:" + ex.Message);
                return string.Empty;
            }
        }

        /// <summary>
        /// 登录失败日志
        /// </summary>
        /// <param name="type"></param>
        /// <param name="custName"></param>
        /// <param name="custPwd"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public string LoginFailedLog(byte type, string custName, string custPwd, string ip)
        {
            try
            {
                int result = BLL.LoginFailedLog.InsertLoginFailedLog(type, custName, custPwd, ip);
                if (result > 0)
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "LoginFailedLog(" + type + ", " + custName + "," + custPwd + ", " + ip + ") error:" + ex.Message);
                return string.Empty;
            }
        }
        #region 后台
        #region 产品
        //获取保险公司下拉列表
        public string GetInsCompanyDropList()
        {
            try
            {
                List<Model.InsCompany> companyList = new List<Model.InsCompany>();

                companyList = BLL.InsCompany.GetInsCompanyDropList();

                if (companyList == null || companyList.Count == 0) return string.Empty;

                Response<List<Model.InsCompany>> el = new Response<List<Model.InsCompany>>();
                el.Status = "SUC";
                el.Result = companyList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "GetInsCompanyDropList() error:" + ex.Message);
                return string.Empty;
            }
        }

        //获取保险种类下拉列表
        public string GetInsTypeDropList()
        {
            try
            {
                List<Model.InsType> typeList = new List<Model.InsType>();

                typeList = BLL.InsType.GetInsTypeDropList();

                if (typeList == null || typeList.Count == 0) return string.Empty;

                Response<List<Model.InsType>> el = new Response<List<Model.InsType>>();
                el.Status = "SUC";
                el.Result = typeList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "GetInsTypeDropList() error:" + ex.Message);
                return string.Empty;
            }
        }

        //获取供应商下拉列表
        public string GetSupDropList()
        {
            try
            {
                List<Model.SupInfo> supList = new List<Model.SupInfo>();

                supList = BLL.SupInfo.GetSupInfoDropList();

                if (supList == null || supList.Count == 0) return string.Empty;

                Response<List<Model.SupInfo>> el = new Response<List<Model.SupInfo>>();
                el.Status = "SUC";
                el.Result = supList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "GetSupDropList() error:" + ex.Message);
                return string.Empty;
            }
        }

        //添加产品
        public string AddProduct(int productTypeFid, int productInsFid, int productSupFid, string productName, string productShortName, DateTime productBeginTime, DateTime productEndTime, decimal productPrice, decimal productSettlePrice, int productQuota, int productAgeMin, int productAgeMax, string productIntro, string productDesc, string productOthers, string productFeature, string productServiceDesc, string productTimeDesc, byte productStatus, string productCode)
        {
            try
            {
                Model.ProductInfo proInfo = new Model.ProductInfo();
                proInfo.ProductTypeFid = productTypeFid;
                proInfo.ProductInsFid = productInsFid;
                proInfo.ProductSupFid = productSupFid;
                proInfo.ProductName = productName;
                proInfo.ProductShortName = productShortName;
                proInfo.ProductBeginTime = productBeginTime;
                proInfo.ProductEndTime = productEndTime;
                proInfo.ProductPrice = productPrice;
                proInfo.ProductSettlePrice = productSettlePrice;
                proInfo.ProductQuota = productQuota;
                proInfo.ProductAgeMin = productAgeMin;
                proInfo.ProductAgeMax = productAgeMax;
                proInfo.ProductIntro = productIntro;
                proInfo.ProductDesc = productDesc;
                proInfo.ProductOthers = productOthers;
                proInfo.ProductFeature = productFeature;
                proInfo.ProductServiceDesc = productServiceDesc;
                proInfo.ProductTimeDesc = productTimeDesc;
                proInfo.ProductStatus = productStatus;
                proInfo.ProductCode = productCode;
                if (BLL.ProductInfo.AddProductInfo(proInfo))
                {
                    Response<Model.ProductInfo> el = new Response<Model.ProductInfo>();
                    el.Status = "SUC";
                    el.Result = proInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "AddProduct() error:" + ex.Message);
                return string.Empty;
            }

        }

        //产品分页查询
        public string GetProductList(string proName, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.ProductInfo> proList = new List<Model.ProductInfo>();

                proList = BLL.ProductInfo.GetProductList(proName, pageSize, pageIndex);

                if (proList == null || proList.Count == 0) return string.Empty;

                Response<List<Model.ProductInfo>> el = new Response<List<Model.ProductInfo>>();
                el.Status = "SUC";
                el.Result = proList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductList({0},{1},{2}) error:" + ex.Message, proName, pageSize, pageIndex));
                return string.Empty;
            }
        }

        //获取产品信息
        public string GetProductById(long pid)
        {
            try
            {
                Model.ProductInfo pro = new Model.ProductInfo();

                pro = BLL.ProductInfo.GetProductInfoById(pid);

                if (pro == null) return string.Empty;

                Response<Model.ProductInfo> el = new Response<Model.ProductInfo>();
                el.Status = "SUC";
                el.Result = pro;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductInfoById({0}) error:" + ex.Message, pid));
                return string.Empty;
            }
        }

        //更新产品信息
        public string UpdateProduct(long pid, int productTypeFid, int productInsFid, int productSupFid, string productName, string productShortName, DateTime productBeginTime, DateTime productEndTime, decimal productPrice, decimal productSettlePrice, int productQuota, int productAgeMin, int productAgeMax, string productIntro, string productDesc, string productOthers, string productFeature, string productServiceDesc, string productTimeDesc, byte productStatus, string productCode)
        {
            try
            {
                Model.ProductInfo proInfo = new Model.ProductInfo();
                proInfo.ProductTypeFid = productTypeFid;
                proInfo.ProductInsFid = productInsFid;
                proInfo.ProductSupFid = productSupFid;
                proInfo.ProductName = productName;
                proInfo.ProductShortName = productShortName;
                proInfo.ProductBeginTime = productBeginTime;
                proInfo.ProductEndTime = productEndTime;
                proInfo.ProductPrice = productPrice;
                proInfo.ProductSettlePrice = productSettlePrice;
                proInfo.ProductQuota = productQuota;
                proInfo.ProductAgeMin = productAgeMin;
                proInfo.ProductAgeMax = productAgeMax;
                proInfo.ProductIntro = productIntro;
                proInfo.ProductDesc = productDesc;
                proInfo.ProductOthers = productOthers;
                proInfo.ProductFeature = productFeature;
                proInfo.ProductServiceDesc = productServiceDesc;
                proInfo.ProductTimeDesc = productTimeDesc;
                proInfo.ProductStatus = productStatus;

                if (BLL.ProductInfo.UpdateProductInfo(pid, proInfo))
                {
                    Response<Model.ProductInfo> el = new Response<Model.ProductInfo>();
                    el.Status = "SUC";
                    el.Result = proInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateProduct() error:" + ex.Message);
                return string.Empty;
            }

        }
        #endregion

        #region 供应商
        //添加供应商
        public string AddSup(string supName, byte supType, string supMark, byte supStatus)
        {
            try
            {
                Model.SupInfo supInfo = new Model.SupInfo();
                supInfo.SupName = supName;
                supInfo.SupType = supType;
                supInfo.SupMark = supMark;
                supInfo.SupStatus = supStatus;

                if (BLL.SupInfo.AddSupInfo(supInfo))
                {
                    Response<Model.SupInfo> el = new Response<Model.SupInfo>();
                    el.Status = "SUC";
                    el.Result = supInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "AddSup() error:" + ex.Message);
                return string.Empty;
            }

        }

        //供应商分页查询
        public string GetSupList(string supName, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.SupInfo> supList = new List<Model.SupInfo>();

                supList = BLL.SupInfo.GetSupList(supName, pageSize, pageIndex);

                if (supList == null || supList.Count == 0) return string.Empty;

                Response<List<Model.SupInfo>> el = new Response<List<Model.SupInfo>>();
                el.Status = "SUC";
                el.Result = supList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetSupInfoList({0},{1},{2}) error:" + ex.Message, supName, pageSize, pageIndex));
                return string.Empty;
            }
        }

        //获取供应商信息
        public string GetSupById(long sid)
        {
            try
            {
                Model.SupInfo sup = new Model.SupInfo();

                sup = BLL.SupInfo.GetSupInfoById(sid);

                if (sup == null) return string.Empty;

                Response<Model.SupInfo> el = new Response<Model.SupInfo>();
                el.Status = "SUC";
                el.Result = sup;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetSupById({0}) error:" + ex.Message, sid));
                return string.Empty;
            }
        }

        //更新产品信息
        public string UpdateSup(long sid, string supName, byte supType, string supMark, byte supStatus)
        {
            try
            {
                Model.SupInfo supInfo = new Model.SupInfo();
                supInfo.SupName = supName;
                supInfo.SupType = supType;
                supInfo.SupMark = supMark;
                supInfo.SupStatus = supStatus;

                if (BLL.SupInfo.UpdateSupInfo(sid, supInfo))
                {
                    Response<Model.SupInfo> el = new Response<Model.SupInfo>();
                    el.Status = "SUC";
                    el.Result = supInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateSup() error:" + ex.Message);
                return string.Empty;
            }
        }
        #endregion

        #region 经销商
        //添加经销商基本信息和扩展信息
        public string AddCust(string custName, string custPwd, string custEmail, long custUserFid, byte custFrom, int custTypeFid, int custLevelFid, byte custStatus, string custMark, string extContactName, string extContactTel, string extContactOthers, string extCompanyName, string extCompanyZip, string extCompanyAddress, string extCompanyTel, string extCompanyFax, string extCompanyEmail, string extCompanyWebsite, string extCompanyReg, string extChargeName, string extFrom)
        {
            try
            {
                Model.CustInfo custInfo = new Model.CustInfo();
                custInfo.CustName = custName;
                custInfo.CustPwd = custPwd;
                custInfo.CustEmail = custEmail;
                custInfo.CustUserFid = custUserFid;
                custInfo.CustFrom = custFrom;
                custInfo.CustTypeFid = custTypeFid;
                custInfo.CustLevelFid = custLevelFid;
                custInfo.CustStatus = custStatus;
                custInfo.CustMark = custMark;

                Model.CustExtInfo custExtInfo = new Model.CustExtInfo();
                custExtInfo.ExtContactName = extContactName;
                custExtInfo.ExtContactTel = extContactTel;
                custExtInfo.ExtContactOthers = extContactOthers;
                custExtInfo.ExtCompanyName = extCompanyName;
                custExtInfo.ExtCompanyZip = extCompanyZip;
                custExtInfo.ExtCompanyAddress = extCompanyAddress;
                custExtInfo.ExtCompanyTel = extCompanyTel;
                custExtInfo.ExtCompanyFax = extCompanyFax;
                custExtInfo.ExtCompanyEmail = extCompanyEmail;
                custExtInfo.ExtCompanyWebsite = extCompanyWebsite;
                custExtInfo.ExtCompanyReg = extCompanyReg;
                custExtInfo.ExtChargeName = extChargeName;
                custExtInfo.ExtFrom = extFrom;
                custExtInfo.ExtContactName = extContactName;
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.CustInfo.AddCustInfo(custInfo, custExtInfo));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "AddCust() error:" + ex.Message);
                return string.Empty;
            }

        }

        //经销商分页查询
        public string GetCustList(string custName, int pageSize, int pageIndex, DateTime start, DateTime end, string type,string userName)
        {
            try
            {
                List<Model.CustInfo> custList = new List<Model.CustInfo>();

                custList = BLL.CustInfo.GetCustList(custName, pageSize, pageIndex, start, end, type,userName);

                if (custList == null || custList.Count == 0) return string.Empty;

                Response<List<Model.CustInfo>> el = new Response<List<Model.CustInfo>>();
                el.Status = "SUC";
                el.Result = custList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustList({0},{1},{2},{3},{4},{5}) error:" + ex.Message, custName, pageSize, pageIndex, start, end, type));
                return string.Empty;
            }
        }

        //获取经销商基本信息
        public string GetCustById(long cid)
        {
            try
            {
                Model.CustInfo cust = new Model.CustInfo();

                cust = BLL.CustInfo.GetCustInfoById(cid);

                if (cust == null) return string.Empty;

                Response<Model.CustInfo> el = new Response<Model.CustInfo>();
                el.Status = "SUC";
                el.Result = cust;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustById({0}) error:" + ex.Message, cid));
                return string.Empty;
            }
        }

        //经销商用户名和邮箱是否存在
        public string CustIsExisted(long cid, string custName, string email)
        {
            try
            {
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.CustInfo.CustIsExisted(cid, custName, email));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("CustIsExist({0},{1}) error:" + ex.Message, custName, email));
                return string.Empty;
            }
        }

        //获取经销商扩展信息
        public string GetCustExtById(long cid)
        {
            try
            {
                Model.CustExtInfo extInfo = new Model.CustExtInfo();

                extInfo = BLL.CustExtInfo.GetCustExtInfoById(cid);

                if (extInfo == null) return string.Empty;

                Response<Model.CustExtInfo> el = new Response<Model.CustExtInfo>();
                el.Status = "SUC";
                el.Result = extInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustExtById({0}) error:" + ex.Message, cid));
                return string.Empty;
            }
        }

        //更新经销商信息
        public string UpdateCustInfo(long cid, string custPwd, string custEmail, long custUserFid, byte custFrom, int custTypeFid, int custLevelFid, byte custStatus, string custMark, string extContactName, string extContactTel, string extContactOthers, string extCompanyName, string extCompanyZip, string extCompanyAddress, string extCompanyTel, string extCompanyFax, string extCompanyEmail, string extCompanyWebsite, string extCompanyReg, string extChargeName, string extFrom)
        {
            try
            {
                Model.CustInfo custInfo = new Model.CustInfo();
                custInfo.CustPwd = custPwd;
                custInfo.CustEmail = custEmail;
                custInfo.CustUserFid = custUserFid;
                custInfo.CustFrom = custFrom;
                custInfo.CustTypeFid = custTypeFid;
                custInfo.CustLevelFid = custLevelFid;
                custInfo.CustStatus = custStatus;
                custInfo.CustMark = custMark;

                Model.CustExtInfo custExtInfo = new Model.CustExtInfo();
                custExtInfo.ExtContactName = extContactName;
                custExtInfo.ExtContactTel = extContactTel;
                custExtInfo.ExtContactOthers = extContactOthers;
                custExtInfo.ExtCompanyName = extCompanyName;
                custExtInfo.ExtCompanyZip = extCompanyZip;
                custExtInfo.ExtCompanyAddress = extCompanyAddress;
                custExtInfo.ExtCompanyTel = extCompanyTel;
                custExtInfo.ExtCompanyFax = extCompanyFax;
                custExtInfo.ExtCompanyEmail = extCompanyEmail;
                custExtInfo.ExtCompanyWebsite = extCompanyWebsite;
                custExtInfo.ExtCompanyReg = extCompanyReg;
                custExtInfo.ExtChargeName = extChargeName;
                custExtInfo.ExtFrom = extFrom;
                custExtInfo.ExtContactName = extContactName;

                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.CustInfo.UpdateCustInfo(cid, custInfo, custExtInfo));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateCust() error:" + ex.Message);
                return string.Empty;
            }
        }

        //更新经销商基本信息
        public string UpdateCust(long cid, string custPwd, string custEmail, long custUserFid, byte custFrom, int custTypeFid, int custLevelFid, byte custStatus, string custMark)
        {
            try
            {
                Model.CustInfo custInfo = new Model.CustInfo();
                custInfo.CustPwd = custPwd;
                custInfo.CustEmail = custEmail;
                custInfo.CustUserFid = custUserFid;
                custInfo.CustFrom = custFrom;
                custInfo.CustTypeFid = custTypeFid;
                custInfo.CustLevelFid = custLevelFid;
                custInfo.CustStatus = custStatus;
                custInfo.CustMark = custMark;

                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.CustInfo.UpdateCustInfo(cid, custInfo));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateCust() error:" + ex.Message);
                return string.Empty;
            }
        }

        //更新经销商扩展信息
        public string UpdateCustExt(long cid, string extContactName, string extContactTel, string extContactOthers, string extCompanyName, string extCompanyZip, string extCompanyAddress, string extCompanyTel, string extCompanyFax, string extCompanyEmail, string extCompanyWebsite, string extCompanyReg, string extChargeName, string extFrom)
        {
            try
            {
                Model.CustExtInfo custExtInfo = new Model.CustExtInfo();
                custExtInfo.ExtContactName = extContactName;
                custExtInfo.ExtContactTel = extContactTel;
                custExtInfo.ExtContactOthers = extContactOthers;
                custExtInfo.ExtCompanyName = extCompanyName;
                custExtInfo.ExtCompanyZip = extCompanyZip;
                custExtInfo.ExtCompanyAddress = extCompanyAddress;
                custExtInfo.ExtCompanyTel = extCompanyTel;
                custExtInfo.ExtCompanyFax = extCompanyFax;
                custExtInfo.ExtCompanyEmail = extCompanyEmail;
                custExtInfo.ExtCompanyWebsite = extCompanyWebsite;
                custExtInfo.ExtCompanyReg = extCompanyReg;
                custExtInfo.ExtChargeName = extChargeName;
                custExtInfo.ExtFrom = extFrom;
                custExtInfo.ExtContactName = extContactName;

                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.CustExtInfo.UpdateCustExtInfo(cid, custExtInfo));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateCustExt() error:" + ex.Message);
                return string.Empty;
            }
        }

        //获取员工下拉列表
        public string GetUserDropList()
        {
            try
            {
                List<Model.UserInfo> userList = new List<Model.UserInfo>();

                userList = BLL.UserInfo.GetUserDropList();

                if (userList == null || userList.Count == 0) return string.Empty;

                Response<List<Model.UserInfo>> el = new Response<List<Model.UserInfo>>();
                el.Status = "SUC";
                el.Result = userList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUserDropList({0}) error:" + ex.Message));
                return string.Empty;
            }
        }

        //获取经销商级别下拉列表
        public string GetCustLevelDropList()
        {
            try
            {
                List<Model.CustLevel> userList = new List<Model.CustLevel>();

                userList = BLL.CustLevel.GetCustLevelDropList();

                if (userList == null || userList.Count == 0) return string.Empty;

                Response<List<Model.CustLevel>> el = new Response<List<Model.CustLevel>>();
                el.Status = "SUC";
                el.Result = userList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "GetCustLevelDropList() error:" + ex.Message);
                return string.Empty;
            }
        }

        //获取经销商类别下拉列表
        public string GetCustTypeDropList()
        {
            try
            {
                List<Model.CustType> userList = new List<Model.CustType>();

                userList = BLL.CustType.GetCustTypeDropList();

                if (userList == null || userList.Count == 0) return string.Empty;

                Response<List<Model.CustType>> el = new Response<List<Model.CustType>>();
                el.Status = "SUC";
                el.Result = userList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "GetCustTypeDropList() error:" + ex.Message);
                return string.Empty;
            }
        }
        //添加/修改销售员
        public string AddSalesRelation(long custId, long userId, int type,long UserId)
        {
            try
            {
                bool result = BLL.SalesRelation.AddSalesRelation(custId, userId, type,UserId);
                if (result == false)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("AddSalesRelation({0},{1},{2},{3})err:" + ex.Message, custId, userId, type,UserId));
                return string.Empty;
            }
        }
        //备份经销商其他信息
        public string AddCustInfoBack(long custFid, string extContactName, string extContactTel, string extContactOthers, string extCompanyName, string extCompanyZip, string extCompanyAddress, string extCompanyTel, string extCompanyFax, string extCompanyEmail, string extCompanyWebsite, string extCompanyReg, string extChargeName, string extFrom, long userId)
        {
            try
            {
                bool result = BLL.CustExtInfoBack.AddCustInfoBack(custFid, extContactName, extContactTel, extContactOthers, extCompanyName, extCompanyZip, extCompanyAddress, extCompanyTel, extCompanyFax, extCompanyEmail, extCompanyWebsite, extCompanyReg, extChargeName, extFrom, userId);
                if (result == false)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("stringAddCustInfoBack({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14})err:" + ex.Message, custFid, extContactName, extContactTel, extContactOthers, extCompanyName, extCompanyZip, extCompanyAddress, extCompanyTel, extCompanyFax, extCompanyEmail, extCompanyWebsite, extCompanyReg, extChargeName, extFrom, userId));
                return string.Empty;
            }
        }
        //查询用户登录日志
        public string GetLoginLog(long createBy, byte type)
        {
            try
            {
                List<Model.LoginLog> logList = new List<com.huigo.Framework.Model.LoginLog>();
                logList = BLL.LoginLog.GetLoginLog(createBy, type);
                if (logList == null || logList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.LoginLog>> el = new Response<List<com.huigo.Framework.Model.LoginLog>>();
                    el.Status = "SUC";
                    el.Result = logList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetLoginLog({0},{1})err:" + ex.Message, createBy, type));
                return string.Empty;
            }
        }
        //销售员查询经销商
        public string GetCustListBySales(string custName, int pageSize, int pageIndex, DateTime start, DateTime end, string contactName, string companyName)
        {
            try
            {
                List<Model.CustInfo> custList = new List<com.huigo.Framework.Model.CustInfo>();
                custList = BLL.CustInfo.GetCustListBySales(custName, pageSize, pageIndex, start, end, contactName, companyName);
                if (custList == null || custList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.CustInfo>> el = new Response<List<com.huigo.Framework.Model.CustInfo>>();
                    el.Status = "SUC";
                    el.Result = custList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustListBySales({0},{1},{3},{4},{5},{6})err:" + ex.Message, custName, pageSize, pageIndex, start, end, contactName, companyName));
                return string.Empty;
            }
        }
        //统计经销商
        public string GetSalesRelation(DateTime start, DateTime end, long userId)
        {
            try
            {
                List<Model.SalesRelation> sales = new List<com.huigo.Framework.Model.SalesRelation>();
                sales = BLL.SalesRelation.GetSalesRelation(start, end, userId);
                if (sales == null || sales.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.SalesRelation>> el = new Response<List<com.huigo.Framework.Model.SalesRelation>>();
                    el.Status = "SUC";
                    el.Result = sales;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetSalesRelation({0},{1},{2})err:" + ex.Message, start, end, userId));
                return string.Empty;
            }
        }
        //查询经销商统计明细
        public string GetSalesDetail(DateTime start, DateTime end, long custFid, long userId)
        {
            try
            {
                List<Model.SalesRelation> sales = new List<com.huigo.Framework.Model.SalesRelation>();
                sales = BLL.SalesRelation.GetSalesDetail(start, end, custFid, userId);
                if (sales == null || sales.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.SalesRelation>> el = new Response<List<com.huigo.Framework.Model.SalesRelation>>();
                    el.Status = "SUC";
                    el.Result = sales;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetSalesDetail({0},{1},{2},{3})err:" + ex.Message, start, end, custFid, userId));
                return string.Empty;
            }
        }
        //销售绩效统计
        public string GetTotalSales(DateTime start, DateTime end, long userId, string productName, int type)
        {
            try
            {
                List<Model.SalesRelation> salesList = new List<com.huigo.Framework.Model.SalesRelation>();
                salesList = BLL.SalesRelation.GetTotalSales(start, end, userId, productName, type);
                if (salesList == null || salesList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.SalesRelation>> el = new Response<List<com.huigo.Framework.Model.SalesRelation>>();
                    el.Status = "SUC";
                    el.Result = salesList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetTotalSales({0},{1},{2},{3},{4})err:" + ex.Message, start, end, userId, productName, type));
                return string.Empty;
            }
        }
        //查询销售绩效统计明细
        public string GetTotalSalesDetail(DateTime start, DateTime end, long userId, string productName)
        {
            try
            {
                List<Model.SalesRelation> salesList = new List<com.huigo.Framework.Model.SalesRelation>();
                salesList = BLL.SalesRelation.GetSalesDetail(start, end, userId, productName);
                if (salesList == null || salesList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.SalesRelation>> el = new Response<List<com.huigo.Framework.Model.SalesRelation>>();
                    el.Status = "SUC";
                    el.Result = salesList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetTotalSales({0},{1},{2},{3})err:" + ex.Message, start, end, userId, productName));
                return string.Empty;
            }
        }
        #endregion

        #region 保险公司
        //添加保险公司
        public string AddInsCompany(string insName, string insShortName, string insLogo, string insWebSite, string insEX, byte insStatus)
        {
            try
            {
                Model.InsCompany insInfo = new Model.InsCompany();
                insInfo.CompanyName = insName;
                insInfo.CompanyShortName = insShortName;
                insInfo.CompanyLogo = insLogo;
                insInfo.CompanyWebsite = insWebSite;
                insInfo.CompanyEx = insEX;
                insInfo.CompanyStatus = insStatus;
                if (BLL.InsCompany.AddInsCompany(insInfo))
                {
                    Response<Model.InsCompany> el = new Response<Model.InsCompany>();
                    el.Status = "SUC";
                    el.Result = insInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "AddInsCompany() error:" + ex.Message);
                return string.Empty;
            }

        }

        //保险公司分页查询
        public string GetInsCompany(int pageSize, int pageIndex)
        {
            try
            {
                List<Model.InsCompany> supList = new List<Model.InsCompany>();

                supList = BLL.InsCompany.GetInsCompany(pageSize, pageIndex);

                if (supList == null || supList.Count == 0) return string.Empty;

                Response<List<Model.InsCompany>> el = new Response<List<Model.InsCompany>>();
                el.Status = "SUC";
                el.Result = supList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInsCompany({0},{1}) error:" + ex.Message, pageSize, pageIndex));
                return string.Empty;
            }
        }

        //获取保险公司信息
        public string GetInsCompanyById(long sid)
        {
            try
            {
                Model.InsCompany ins = new Model.InsCompany();

                ins = BLL.InsCompany.GetInsCompanyByID(sid);

                if (ins == null) return string.Empty;

                Response<Model.InsCompany> el = new Response<Model.InsCompany>();
                el.Status = "SUC";
                el.Result = ins;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInsCompanyID({0}) error:" + ex.Message, sid));
                return string.Empty;
            }
        }
        //验证保险公司是否存在
        public string GetInsCompanyList(long companyID, string insName, string insMeno, string insEX)
        {
            try
            {
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.InsCompany.GetInsCompanyList(companyID, insName, insMeno, insEX));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("insName({0},{1},{2}) error:" + ex.Message, insName, insMeno, insEX));
                return string.Empty;
            }
        }
        //更新保险公司
        public string UpdateInsCompanyInfo(long sid, string insName, string insMeno, string insWebSite, string insLogo, string insEX, byte insStatus)
        {
            try
            {
                Model.InsCompany insInfo = new Model.InsCompany();
                insInfo.CompanyName = insName;
                insInfo.CompanyShortName = insMeno;
                insInfo.CompanyLogo = insLogo;
                insInfo.CompanyWebsite = insWebSite;
                insInfo.CompanyStatus = insStatus;

                if (BLL.InsCompany.UpdateInsCompanyInfo(sid, insInfo))
                {
                    Response<Model.InsCompany> el = new Response<Model.InsCompany>();
                    el.Status = "SUC";
                    el.Result = insInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateInsCompanyInfo() error:" + ex.Message);
                return string.Empty;
            }
        }

        #endregion

        #region 员工管理
        //查询用户信息
        public string GetUserInfo(string userName, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.UserInfo> proList = new List<Model.UserInfo>();

                proList = BLL.UserInfo.GetUserInfo(userName, pageSize, pageIndex);

                if (proList == null || proList.Count == 0) return string.Empty;

                Response<List<Model.UserInfo>> el = new Response<List<Model.UserInfo>>();
                el.Status = "SUC";
                el.Result = proList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductListByInsType({0},{1},{2}) error:" + ex.Message, userName, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //添加权限
        public string AddUserInfo(string userRalName, string userNum, int userPart, string userName, string userPwd, string userRose, byte insStatus, long creatBY)
        {
            try
            {
                Model.UserInfo userInfo = new Model.UserInfo();
                userInfo.UserRealName = userRalName;
                userInfo.UserDeptFid = userPart;
                userInfo.UserName = userName;
                userInfo.UserPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(userPwd, "MD5");
                userInfo.UserRoleFids = userRose;
                userInfo.UserIsActive = insStatus;
                userInfo.UserCreatedBy = creatBY;
                userInfo.UserNum = userNum;
                if (BLL.UserInfo.AddUserInfo(userInfo))
                {
                    Response<Model.UserInfo> el = new Response<Model.UserInfo>();
                    el.Status = "SUC";
                    el.Result = userInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "AddInsCompany() error:" + ex.Message);
                return string.Empty;
            }

        }
        //更新用户信息
        public string UpdateUserInfo(long sid, int userPart, string userPwd, string userRose, byte insStatus, long creatBY, string userNum)
        {
            try
            {
                Model.UserInfo insInfo = new Model.UserInfo();
                insInfo.UserDeptFid = userPart;
                if (!string.IsNullOrEmpty(userPwd))
                {
                    insInfo.UserPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(userPwd, "MD5");
                }
                insInfo.UserRoleFids = userRose == string.Empty ? "0" : userRose;
                insInfo.UserIsActive = insStatus;
                insInfo.UserLastActivedOn = DateTime.Now;
                insInfo.UserCreatedBy = creatBY;
                insInfo.UserNum = userNum;
                if (BLL.UserInfo.UpdateUserInfo(sid, insInfo))
                {
                    Response<Model.UserInfo> el = new Response<Model.UserInfo>();
                    el.Status = "SUC";
                    el.Result = insInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateInsCompanyInfo() error:" + ex.Message);
                return string.Empty;
            }
        }
        public string GetUserInfoList(long ID, string userName, string userRealName)
        {
            try
            {
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.UserInfo.GetUserInfoList(ID, userName, userRealName));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUserInfoList({0},{1}) error:" + ex.Message, userName, userRealName));
                return string.Empty;
            }
        }
        //查询角色
        public string GetUserRoleList()
        {
            try
            {
                List<Model.UserRole> userRole = new List<Model.UserRole>();

                userRole = BLL.UserRole.GetUserRoleList();

                if (userRole == null || userRole.Count == 0) return string.Empty;

                Response<List<Model.UserRole>> el = new Response<List<Model.UserRole>>();
                el.Status = "SUC";
                el.Result = userRole;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUserRoleList() error:" + ex.Message));
                return string.Empty;
            }
        }
        //查询部门
        public string GetUserDeptList()
        {
            try
            {
                List<Model.UserDept> userRole = new List<Model.UserDept>();

                userRole = BLL.UserDept.GetUserDeptList();

                if (userRole == null || userRole.Count == 0) return string.Empty;

                Response<List<Model.UserDept>> el = new Response<List<Model.UserDept>>();
                el.Status = "SUC";
                el.Result = userRole;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUserRoleList() error:" + ex.Message));
                return string.Empty;
            }
        }
        public string GetUserInfoById(long sid)
        {
            try
            {
                Model.UserInfo ins = new Model.UserInfo();

                ins = BLL.UserInfo.GetUserInfoById(sid);

                if (ins == null) return string.Empty;

                Response<Model.UserInfo> el = new Response<Model.UserInfo>();
                el.Status = "SUC";
                el.Result = ins;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUserInfoById({0}) error:" + ex.Message, sid));
                return string.Empty;
            }
        }
        #endregion

        #region 订单
        //订单分页查询
        public string GetOrderInfo(string orderNO, DateTime orderStart, DateTime orderEnd, string policyNo, string policyInsName, string custName, int orderType, long insCompanyId, long proType, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.OrderInfo> orderInfo = new List<Model.OrderInfo>();

                orderInfo = BLL.OrderInfo.GetOrderInfo(orderNO, orderStart, orderEnd, policyNo, policyInsName, custName, orderType, insCompanyId, proType, pageSize, pageIndex);

                if (orderInfo == null || orderInfo.Count == 0) return string.Empty;

                Response<List<Model.OrderInfo>> el = new Response<List<Model.OrderInfo>>();
                el.Status = "SUC";
                el.Result = orderInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderInfo({0},{1},{2},{3},{4},{5},{6},{7},{8}) error:" + ex.Message, orderNO, orderStart, orderEnd, orderType, insCompanyId, proType, pageSize, pageIndex));
                return string.Empty;
            }
        }

        //查询订单详细
        public string GetOrderInfoById(long sid)
        {
            try
            {
                Model.OrderInfo ins = new Model.OrderInfo();

                ins = BLL.OrderInfo.GetOrderInfoById(sid);

                if (ins == null) return string.Empty;

                Response<Model.OrderInfo> el = new Response<Model.OrderInfo>();
                el.Status = "SUC";
                el.Result = ins;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderInfoById({0}) error:" + ex.Message, sid));
                return string.Empty;
            }
        }

        //保险订单扩展表-航意险
        public string GetPolicyInfoAirList(long orderFid)
        {
            try
            {
                List<Model.PolicyInfoAir> PolicyInfo = new List<Model.PolicyInfoAir>();

                PolicyInfo = BLL.PolicyInfoAir.GetPolicyInfoAirList(orderFid);

                if (PolicyInfo == null || PolicyInfo.Count == 0) return string.Empty;

                Response<List<Model.PolicyInfoAir>> el = new Response<List<Model.PolicyInfoAir>>();
                el.Status = "SUC";
                el.Result = PolicyInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetPolicyInfoAirList({0}) error:" + ex.Message, orderFid));
                return string.Empty;
            }
        }

        //保险订单扩展表-旅游险
        public string GetPolicyInfoTravelList(long orderFid)
        {
            try
            {
                List<Model.PolicyInfoTravel> orderInfo = new List<Model.PolicyInfoTravel>();

                orderInfo = BLL.PolicyInfoTravel.GetPolicyInfoTravelList(orderFid);

                if (orderInfo == null || orderInfo.Count == 0) return string.Empty;

                Response<List<Model.PolicyInfoTravel>> el = new Response<List<Model.PolicyInfoTravel>>();
                el.Status = "SUC";
                el.Result = orderInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetPolicyInfoTravelList({0}) error:" + ex.Message, orderFid));
                return string.Empty;
            }
        }

        //查询订单操作流
        public string GetOrderFlowList(long orderFid)
        {
            try
            {
                List<Model.OrderFlow> orderFlowInfo = new List<Model.OrderFlow>();

                orderFlowInfo = BLL.OrderFlow.GetOrderFlowList(orderFid);

                if (orderFlowInfo == null || orderFlowInfo.Count == 0) return string.Empty;

                Response<List<Model.OrderFlow>> el = new Response<List<Model.OrderFlow>>();
                el.Status = "SUC";
                el.Result = orderFlowInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderFlowList({0}) error:" + ex.Message, orderFid));
                return string.Empty;
            }
        }
        //查询保单操作流
        public string GetPolicyFlowList(long policyFid)
        {
            try
            {
                List<Model.PolicyFlow> PolicyFlowInfo = new List<Model.PolicyFlow>();

                PolicyFlowInfo = BLL.PolicyFlow.GetPolicyFlowList(policyFid);

                if (PolicyFlowInfo == null || PolicyFlowInfo.Count == 0) return string.Empty;

                Response<List<Model.PolicyFlow>> el = new Response<List<Model.PolicyFlow>>();
                el.Status = "SUC";
                el.Result = PolicyFlowInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetPolicyFlowList({0}) error:" + ex.Message, policyFid));
                return string.Empty;
            }
        }
        //修改订单状态
        public string UpdateOrderInfoStatus(long OrderID, int OrderStatusFid, long userID)
        {
            try
            {
                OneResult oneResult = new OneResult();
                Response<OneResult> el = new Response<OneResult>();
                if (BLL.OrderInfo.UpdateOrderInfoStatus(OrderID, OrderStatusFid, userID))
                {
                    el.Status = "SUC";
                    oneResult.returnargs = 1;
                    el.Result = oneResult;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdateOrderInfoStatus() error:" + ex.Message);
                return string.Empty;
            }
        }
        //修改保单状态
        public string UpdatePolicyInfoAirStatus(string PolicyID, long userID, int type)
        {
            try
            {
                OneResult oneResult = new OneResult();
                Response<OneResult> el = new Response<OneResult>();
                if (BLL.PolicyInfoAir.UpdatPolicyInfoAirStatus(PolicyID, userID, type))
                {
                    el.Status = "SUC";
                    oneResult.returnargs = 1;
                    el.Result = oneResult;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "UpdatPolicyInfoAirStatus() error:" + ex.Message);
                return string.Empty;
            }
        }
        //根据订单id查询保单状态
        public string GetPolicyInfoAirById(long id)
        {
            try
            {
                Model.PolicyInfoAir ins = new Model.PolicyInfoAir();

                ins = BLL.PolicyInfoAir.GetPolicyInfoAirById(id);

                if (ins == null) return string.Empty;

                Response<Model.PolicyInfoAir> el = new Response<Model.PolicyInfoAir>();
                el.Status = "SUC";
                el.Result = ins;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetPolicyInfoAirById({0}) error:" + ex.Message, id));
                return string.Empty;
            }
        }

        //保单是否存在
        public string PolicyInfoAirIsExisted(long cid)
        {
            try
            {
                List<Model.PolicyInfoAir> PolicyInfo = new List<Model.PolicyInfoAir>();

                PolicyInfo = BLL.PolicyInfoAir.PolicyInfoAirIsExisted(cid);

                if (PolicyInfo == null || PolicyInfo.Count == 0) return string.Empty;

                Response<List<Model.PolicyInfoAir>> el = new Response<List<Model.PolicyInfoAir>>();
                el.Status = "SUC";
                el.Result = PolicyInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("PolicyInfoAirIsExisted() error:" + ex.Message));
                return string.Empty;
            }
        }
        //订单是否存在
        public string OrderInfoIsExisted(long cid, int orderStaus)
        {
            try
            {
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(BLL.OrderInfo.OrderInfoIsExisted(cid, orderStaus));
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("OrderInfoIsExisted({0}) error:" + ex.Message, orderStaus));
                return string.Empty;
            }
        }

        #endregion

        #region 发票申领管理
        public string GetInvoiceOrderInfo(string InvoiceOrderNO, DateTime InvoiceOrderStart, DateTime InvoiceOrderEnd, string custName, int InvoiceOrderStatus, string proName, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.InvoiceOrder> InvoiceOrderList = new List<Model.InvoiceOrder>();

                InvoiceOrderList = BLL.InvoiceOrder.GetInvoiceOrderInfo(InvoiceOrderNO, InvoiceOrderStart, InvoiceOrderEnd, custName, InvoiceOrderStatus, proName, pageSize, pageIndex);

                if (InvoiceOrderList == null || InvoiceOrderList.Count == 0) return string.Empty;

                Response<List<Model.InvoiceOrder>> el = new Response<List<Model.InvoiceOrder>>();
                el.Status = "SUC";
                el.Result = InvoiceOrderList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInvoiceOrderInfo({0},{1},{2},{3},{4},{5},{6}) error:" + ex.Message, InvoiceOrderNO, InvoiceOrderStart, InvoiceOrderEnd, custName, InvoiceOrderStatus, proName, pageSize, pageIndex));
                return string.Empty;
            }
        }

        //查询 发票订单操作流
        public string GetInvoiceOrderFlowList(long orderFid)
        {
            try
            {
                List<Model.InvoiceOrderFlow> InvoiceorderFlowInfo = new List<Model.InvoiceOrderFlow>();

                InvoiceorderFlowInfo = BLL.InvoiceOrderFlow.GetInvoiceOrderFlowList(orderFid);

                if (InvoiceorderFlowInfo == null || InvoiceorderFlowInfo.Count == 0) return string.Empty;

                Response<List<Model.InvoiceOrderFlow>> el = new Response<List<Model.InvoiceOrderFlow>>();
                el.Status = "SUC";
                el.Result = InvoiceorderFlowInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderFlowList({0}) error:" + ex.Message, orderFid));
                return string.Empty;
            }
        }
        //获取产品名称
        public string GetProductListName()
        {
            try {
                List<Model.ProductInfo> product = new List<com.huigo.Framework.Model.ProductInfo>();
                product = BLL.ProductInfo.GetProductListName();
                if (product == null || product.Count == 0) return string.Empty;
                Response<List<Model.ProductInfo>> el = new Response<List<com.huigo.Framework.Model.ProductInfo>>();
                el.Status = "SUC";
                el.Result = product;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductListName() error:" + ex.Message));
                return string.Empty;
            }
        }
        //更新订单表
        public string updateInvoiceOrder(long invoiceOrderID, int status, long userID, string Meno, string Fedex, string FedexComPany)
        {
            try
            {
                bool result = BLL.InvoiceOrder.updateInvoiceOrder(invoiceOrderID, status, userID, Meno, Fedex, FedexComPany);
                if (result)
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "updateInvoiceOrder("+ invoiceOrderID + "," + status + ","+userID+","+Meno+","+ Fedex+","+ FedexComPany+") error:" + ex.Message);
                return string.Empty;
            }
        }
        //查询订单详情
        public string GetInvoiceOrderByID(long invoiceOrderID)
        {
            try
            {
                Model.InvoiceOrder order = new Model.InvoiceOrder();

                order = BLL.InvoiceOrder.GetInvoiceOrderByID(invoiceOrderID);

                if (order == null) return string.Empty;

                Response<Model.InvoiceOrder> el = new Response<Model.InvoiceOrder>();
                el.Status = "SUC";
                el.Result = order;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInvoiceOrderByID({0}) error:" + ex.Message, invoiceOrderID));
                return string.Empty;
            }
        }

        //航意险
        public string GetInvoiceOrderPolicyAirCustName(long custFID, int insType, long orderID, int pageSize, int pageIndex, DateTime orderStart, DateTime orderEnd)
        {
            try
            {
                List<Model.PolicyInfoAir> PolicyInfoAir = new List<Model.PolicyInfoAir>();

                PolicyInfoAir = BLL.PolicyInfoAir.GetInvoiceOrderPolicyAirCustName(custFID,insType, orderID, pageSize, pageIndex, orderStart,  orderEnd);

                if (PolicyInfoAir == null || PolicyInfoAir.Count == 0) return string.Empty;

                Response<List<Model.PolicyInfoAir>> el = new Response<List<Model.PolicyInfoAir>>();
                el.Status = "SUC";
                el.Result = PolicyInfoAir;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInvoiceOrderPolicyAirCustName({0},{1},{2},{3},{4},{5},{6}) error:" + ex.Message, custFID, orderID, pageSize, pageIndex,orderStart, orderEnd,insType));
                return string.Empty;
            }
        }
        //旅游险
        public string GetInvoiceOrderPolicyTravelCustName(long custFID,int insType, long orderID, int pageSize, int pageIndex, DateTime orderStart, DateTime orderEnd)
        {
            try
            {
                List<Model.PolicyInfoTravel> PolicyInfoTravel = new List<Model.PolicyInfoTravel>();

                PolicyInfoTravel = BLL.PolicyInfoTravel.GetInvoiceOrderPolicyTravelCustName( custFID,insType, orderID,  pageSize,  pageIndex, orderStart,  orderEnd);

                if (PolicyInfoTravel == null || PolicyInfoTravel.Count == 0) return string.Empty;

                Response<List<Model.PolicyInfoTravel>> el = new Response<List<Model.PolicyInfoTravel>>();
                el.Status = "SUC";
                el.Result = PolicyInfoTravel;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInvoiceOrderPolicyTravelCustName({0},{1},{2},{3},{4},{5},{6}) error:" + ex.Message, custFID, orderID, pageSize, pageIndex, orderStart, orderEnd, insType));
                return string.Empty;
            }
        }
        #endregion

        #region  财务
        /// <summary>
        /// 充值列表查询
        /// </summary>
        /// <param name="custName">经销商</param>
        /// <param name="channel">支付方式</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="payNo">支付交易号</param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public string GetCustFeeFlowPayList(string custName, string channel, DateTime start, DateTime end, string payNo, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.CustFeeFlow> CustFeeFlowList = new List<Model.CustFeeFlow>();

                CustFeeFlowList = BLL.CustFeeFlow.GetCustFeeFlowPayList( custName,  channel,  start,  end,  payNo,  pageSize,  pageIndex);

                if (CustFeeFlowList == null || CustFeeFlowList.Count == 0) return string.Empty;

                Response<List<Model.CustFeeFlow>> el = new Response<List<Model.CustFeeFlow>>();
                el.Status = "SUC";
                el.Result = CustFeeFlowList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustFeeFlowPayList({0},{1},{2},{3},{4},{5},{6}) error:" + ex.Message, custName, channel, start, end, payNo, pageSize, pageIndex));
                return string.Empty;
            }
        }
        /// <summary>
        /// 消费流列表查询
        /// </summary>
        /// <param name="custName">经销商</param>
        /// <param name="orderNO">订单号</param>
        /// <param name="flowType">消费类型</param>
        /// <param name="orderStatus">订单类型</param>
        /// <param name="start">时间</param>
        /// <param name="end">时间</param>
        /// <param name="payNo">支付交易号</param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public string GetCustFeeFlowInfoList(string custName, string orderNO, int flowType, int orderStatus, DateTime start, DateTime end, string payNo, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.CustFeeFlow> CustFeeFlowList = new List<Model.CustFeeFlow>();

                CustFeeFlowList = BLL.CustFeeFlow.GetCustFeeFlowInfoList(custName, orderNO, flowType, orderStatus, start, end, payNo, pageSize, pageIndex);

                if (CustFeeFlowList == null || CustFeeFlowList.Count == 0) return string.Empty;

                Response<List<Model.CustFeeFlow>> el = new Response<List<Model.CustFeeFlow>>();
                el.Status = "SUC";
                el.Result = CustFeeFlowList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustFeeFlowPayList({0},{1},{2},{3},{4},{5},{6},{7},{8}) error:" + ex.Message, custName, orderNO, flowType, orderStatus, start, end, payNo, pageSize, pageIndex));
                return string.Empty;
            }
        }


        //手动充值
        public string InsertPayFeeFLow(long idCustFid, long userID, string payNo, string meno, decimal PayFee, string channel)
        {
            try
            {
                bool result = BLL.CustFeeFlow.InsertPayFeeFLow(idCustFid, userID, payNo, meno, PayFee, channel);
                if (result)
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, "InsertPayFeeFLow(" + idCustFid + "," + userID + "," + payNo + "," + meno + "," + PayFee + "," + channel + ") error:" + ex.Message);
                return string.Empty;
            }
        }
        #endregion
        #endregion

        #region 前台
        //产品分页查询  
        public string GetProductListByInsType(int proType, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.ProductInfo> proList = new List<Model.ProductInfo>();

                proList = BLL.ProductInfo.GetProductListByInsType(proType, pageSize, pageIndex);

                if (proList == null || proList.Count == 0) return string.Empty;

                Response<List<Model.ProductInfo>> el = new Response<List<Model.ProductInfo>>();
                el.Status = "SUC";
                el.Result = proList;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductListByInsType({0},{1},{2}) error:" + ex.Message, proType, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //检查用户是否存在       
        public string CheckUserName(string userName)
        {
            try
            {
                Response<Model.CustInfo> el = new Response<com.huigo.Framework.Model.CustInfo>();
                Model.CustInfo custInfo = BLL.CustInfo.GetCustInfoByCustName(userName);
                if (custInfo != null)
                {
                    el.Status = "SUC";
                    el.Result = custInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("CheckUserName({0} error:" + ex.Message, userName));
                return string.Empty;
            }
        }
        //检查邮箱是否存在
        public string CheckUserEmail(string email)
        {
            try
            {
                Response<Model.CustInfo> el = new Response<com.huigo.Framework.Model.CustInfo>();
                Model.CustInfo custInfo = BLL.CustInfo.getCustInfoByCustEmail(email);
                if (custInfo != null)
                {
                    el.Status = "SUC";
                    el.Result = custInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("checkUserEmail({0} error:" + ex.Message, email));
                return string.Empty;
            }
        }
        //经销商注册
        public string InsertCustInfo(string custName, string pwd, string email, string userName, string tel, string from, string otherContacts, string companyName, string companyAddress, string companyZip, string companyTel, string companyWebsit, string companyReg, string chargeName)
        {
            Model.CustInfo custInfo1 = BLL.CustInfo.GetCustInfoByCustName(custName);
            if (custInfo1 != null)
            {
                return string.Empty;
            }
            if (BLL.CustInfo.getCustInfoByCustEmail(email) != null)
            {
                return string.Empty;
            }
            try
            {
                Response<Model.CustInfo> el = new Response<com.huigo.Framework.Model.CustInfo>();
                string md5Pwd = null;
                md5Pwd = new com.loto.Common.ASPMD5().MD5(pwd);
                Model.CustInfo custInfo = new com.huigo.Framework.Model.CustInfo();
                custInfo.CustName = custName;
                custInfo.CustPwd = md5Pwd.ToUpper();
                custInfo.CustEmail = email;
                custInfo.CustTypeFid = 0;
                custInfo.CustFrom = 1;
                custInfo.CustCreatedOn = DateTime.Now;
                custInfo.CustLastActivedOn = DateTime.Now;
                custInfo.CustStatus = 0;

                Model.CustExtInfo custExtInfo = new com.huigo.Framework.Model.CustExtInfo();
                custExtInfo.ExtContactName = userName;
                custExtInfo.ExtContactTel = tel;
                custExtInfo.ExtContactOthers = otherContacts;
                custExtInfo.ExtCompanyName = companyName;
                custExtInfo.ExtCompanyAddress = companyAddress;
                custExtInfo.ExtCompanyZip = companyZip;
                custExtInfo.ExtCompanyTel = companyTel;
                custExtInfo.ExtCompanyWebsite = companyWebsit;
                custExtInfo.ExtCompanyReg = companyReg;
                custExtInfo.ExtChargeName = chargeName;
                custExtInfo.ExtFrom = from;
                long resutl = BLL.CustInfo.insertCustInfo(custInfo, custExtInfo);

                Model.CustInfo cust = BLL.CustInfo.GetCustInfoByCustName(custName);
                el.Status = "SUC";
                el.Result = cust;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("insertCustInfo({0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13} error:" + ex.Message, custName, pwd, email, userName, tel, from, otherContacts, companyName, companyAddress, companyZip, companyTel, companyWebsit, companyReg, chargeName));
                return string.Empty;
            }
        }
        //根据产品ID查询产品明细
        public string GetProductInfoByProductId(long productId)
        {
            try
            {
                Model.ProductInfo productInfo = BLL.ProductInfo.GetProductInfoByProductId(productId);
                if (productInfo == null)
                {
                    return string.Empty;
                }
                else
                {
                    Response<Model.ProductInfo> el = new Response<com.huigo.Framework.Model.ProductInfo>();
                    el.Status = "SUC";
                    el.Result = productInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductInfoByProductId({0}) err:" + ex.Message, productId));
                return string.Empty;
            }
        }
        //查询用户余额
        public string GetCustUsefulFee(long custId)
        {
            try
            {
                Response<Model.CustInfo> el = new Response<com.huigo.Framework.Model.CustInfo>();
                Model.CustInfo custInfo = BLL.CustInfo.GetCustInfoByCustId
(custId);
                if (custInfo != null)
                {
                    el.Status = "SUC";
                    el.Result = custInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustUsefulFee({0} error:" + ex.Message, custId));
                return string.Empty;
            }
        }
        //前台查询订单列表
        public string GetOrderInfoList(string orderNO, DateTime orderStart, DateTime orderEnd, int orderType, long insCompanyId, long proType, long custFid, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.OrderInfo> orderInfo = new List<Model.OrderInfo>();

                orderInfo = BLL.OrderInfo.getOrderInfoList(orderNO, orderStart, orderEnd, orderType, insCompanyId, proType, custFid, pageSize, pageIndex);

                if (orderInfo == null || orderInfo.Count == 0) return string.Empty;

                Response<List<Model.OrderInfo>> el = new Response<List<Model.OrderInfo>>();
                el.Status = "SUC";
                el.Result = orderInfo;
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustList({0},{1},{2},{3},{4},{5},{6},{7}) error:" + ex.Message, orderNO, orderStart, orderEnd, orderType, insCompanyId, proType, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //取消订单
        public string CancelOrderInfo(long orderId, long custFid)
        {
            try
            {
                OneResult oneResult = new OneResult();
                Response<OneResult> el = new Response<OneResult>();
                if (BLL.OrderInfo.CancelOrderInfo(orderId, custFid))
                {
                    el.Status = "SUC";
                    oneResult.returnargs = 1;
                    el.Result = oneResult;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("CancelOrderInfo({0},{1}) error:" + ex.Message, orderId, custFid));
                return string.Empty;
            }
        }
        //查询保单
        public string GetOrderInfoPolicyList(string policyNo, string policyInsuredName, string policyInsuredNo, DateTime start, DateTime end, long type, long custFid, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.OrderInfo> orderInfoList = new List<com.huigo.Framework.Model.OrderInfo>();
                orderInfoList = BLL.OrderInfo.getOrderInfoPolicyList(policyNo, policyInsuredName, policyInsuredNo, start, end, type, custFid, pageSize, pageIndex);
                if (orderInfoList == null || orderInfoList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.OrderInfo>> el = new Response<List<com.huigo.Framework.Model.OrderInfo>>();
                    el.Status = "SUC";
                    el.Result = orderInfoList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("getOrderInfoList({0},{1},{2},{3},{4},{5},{6},{7},{8})err:" + ex.Message, policyNo, policyInsuredName, policyInsuredNo, start, end, type, custFid, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //查询未付款订单
        public string GetUnpaidOrderList(long custFid, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.OrderInfo> orderList = new List<com.huigo.Framework.Model.OrderInfo>();
                orderList = BLL.OrderInfo.getUnpaidOrderList(custFid, pageSize, pageIndex);
                if (orderList == null || orderList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.OrderInfo>> el = new Response<List<com.huigo.Framework.Model.OrderInfo>>();
                    el.Status = "SUC";
                    el.Result = orderList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetUnpaidOrderList({0},{1},{2})err:" + ex.Message, custFid, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //退保
        public string DoCancelPolicy(long orderId, long policyId, long custFid)
        {
            try
            {
                int insType = Convert.ToInt32(policyId % 1000);
                if (policyId > 0)
                {
                    bool result = BLL.Pay.DoCancelPolicy(policyId, custFid);
                    if (result)
                    {
                        Response<OneResult> el = new Response<OneResult>();
                        el.Status = "SUC";
                        el.Result = new OneResult(result);
                        return com.loto.Common.SerializationHelper.GetSerializationString(el);
                    }
                    else
                    {
                        return string.Empty;
                    }
                }
                else
                {
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("DoCancelPolicy({0},{1},{2})err:" + ex.Message, policyId, custFid));
                return string.Empty;
            }
        }
        //查询问题保单
        public string GetProblemPolicyList(long custFid, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.OrderInfo> orderList = new List<com.huigo.Framework.Model.OrderInfo>();
                orderList = BLL.OrderInfo.GetProblemPolicyList(custFid, pageSize, pageIndex);
                if (orderList == null || orderList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.OrderInfo>> el = new Response<List<com.huigo.Framework.Model.OrderInfo>>();
                    el.Status = "SUC";
                    el.Result = orderList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProblemPolicyList({0},{1},{2})err:" + ex.Message, custFid, pageSize, pageIndex));
                return string.Empty;
            }
        }
        //查询问题保单的总数
        public string GetProblemPolicyCount(long custFid)
        {
            try
            {
                int count = BLL.OrderInfo.GetProblemPolicyCount(custFid);
                Response<OneResult> el = new Response<OneResult>();
                el.Status = "SUC";
                el.Result = new OneResult(count);
                return com.loto.Common.SerializationHelper.GetSerializationString(el);
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProblemPolicyCount({0})err:" + ex.Message, custFid));
                return string.Empty;
            }
        }
        //查询保单的最后一条流
        public string GetPolicyFlow(long policyId)
        {
            try
            {
                Model.PolicyFlow policyFlow = new com.huigo.Framework.Model.PolicyFlow();
                policyFlow = BLL.PolicyFlow.GetPolicyFlow(policyId);
                if (policyFlow == null)
                {
                    return string.Empty;
                }
                else
                {
                    Response<Model.PolicyFlow> el = new Response<com.huigo.Framework.Model.PolicyFlow>();
                    el.Status = "SUC";
                    el.Result = policyFlow;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetPolicyFlow({0})err:" + ex.Message, policyId));
                return string.Empty;
            }
        }
        /// <summary>
        /// 查询用户买过的保险产品
        /// </summary>
        /// <param name="custFid"></param>
        /// <returns></returns>
        public string GetOrderProductName(long custFid)
        {
            try
            {
                List<Model.OrderInfo> orderList = new List<com.huigo.Framework.Model.OrderInfo>();
                orderList = BLL.OrderInfo.getOrderProductName(custFid);
                if (orderList == null || orderList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.OrderInfo>> el = new Response<List<com.huigo.Framework.Model.OrderInfo>>();
                    el.Status = "SUC";
                    el.Result = orderList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderProductName({0})err:" + ex.Message, custFid));
                return string.Empty;
            }
        }
        /// <summary>
        /// 查询省份
        /// </summary>
        /// <returns></returns>
        public string GetProvinceList()
        {
            try
            {
                List<Model.Province> province = new List<com.huigo.Framework.Model.Province>();
                province = BLL.Province.GetProvinceList();
                if (province == null || province.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.Province>> el = new Response<List<com.huigo.Framework.Model.Province>>();
                    el.Status = "SUC";
                    el.Result = province;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProvinceList()err:" + ex.Message));
                return string.Empty;
            }
        }
        //根据省份查询城市
        public string GetCityListByProvinceId(int provinceId)
        {
            try
            {
                List<Model.City> city = new List<com.huigo.Framework.Model.City>();
                city = BLL.Province.GetCityListByProvinceId(provinceId);
                if (city == null || city.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.City>> el = new Response<List<com.huigo.Framework.Model.City>>();
                    el.Status = "SUC";
                    el.Result = city;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCityListByProvinceId({0})err:" + ex.Message, provinceId));
                return string.Empty;
            }
        }
        //用户提交申领订单
        public string AddInvoiceOrder(long productId, int count, byte shipping, string province, string city, string address, string contacts, string contactsTel, decimal money, long custFid)
        {
            try
            {
                long result = BLL.InvoiceOrder.AddInvoiceOrder(productId, count, shipping, province, city, address, contacts, contactsTel, money, custFid);
                if (result == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("AddInvoiceOrder({0},{1},{2},{3},{4},{5},{6},{7},{8},{9})err:" + ex.Message, productId, count, shipping, province, city, address, contacts, contactsTel, money, custFid));
                return string.Empty;
            }
        }
        //根据订单ID查询订单信息
        public string GetInvoiceOrderInfoById(long custFid, long orderId)
        {
            try
            {
                Model.InvoiceOrder order = new com.huigo.Framework.Model.InvoiceOrder();
                order = BLL.InvoiceOrder.GetInvoiceOrderInfoById(custFid, orderId);
                if (order == null)
                {
                    return string.Empty;
                }
                else
                {
                    Response<Model.InvoiceOrder> el = new Response<com.huigo.Framework.Model.InvoiceOrder>();
                    el.Status = "SUC";
                    el.Result = order;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetOrderInfoById({0},{1})err:" + ex.Message, custFid, orderId));
                return string.Empty;
            }
        }
        //查询发票
        public string GetInvoiceOrderList(long custFid, string orderNo, DateTime start, DateTime end, int type, long productId, int pageSize, int pageIndex)
        {
            try
            {
                List<Model.InvoiceOrder> orderList = new List<com.huigo.Framework.Model.InvoiceOrder>();
                orderList = BLL.InvoiceOrder.GetInvoiceOrderList(custFid, orderNo, start, end, type, productId, pageSize, pageIndex);
                if (orderList == null || orderList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.InvoiceOrder>> el = new Response<List<com.huigo.Framework.Model.InvoiceOrder>>();
                    el.Status = "SUC";
                    el.Result = orderList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetInvoiceOrderList({0},{1},{2},{3},{4},{5},{6},{7})err:" + ex.Message));
                return string.Empty;
            }
        }
        //查询所有产品
        public string GetProductInfoList()
        {
            try
            {
                List<Model.ProductInfo> productInfo = new List<com.huigo.Framework.Model.ProductInfo>();
                productInfo = BLL.ProductInfo.GetProductInfoList();
                if (productInfo == null || productInfo.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.ProductInfo>> el = new Response<List<com.huigo.Framework.Model.ProductInfo>>();
                    el.Status = "SUC";
                    el.Result = productInfo;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductInfoList()err:" + ex.Message));
                return string.Empty;
            }
        }
        //查询用户消费明细
        public string GetCustFeeFlow(long custFid, DateTime startTime, DateTime endTime, int type, int PageSize, int PageIndex)
        {
            try
            {
                List<Model.CustFeeFlow> custFeeFlow = new List<com.huigo.Framework.Model.CustFeeFlow>();
                custFeeFlow = BLL.CustFeeFlow.GetCustFeeFlow(custFid,startTime,endTime,type,PageSize,PageIndex);
                if (custFeeFlow == null || custFeeFlow.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.CustFeeFlow>> el = new Response<List<com.huigo.Framework.Model.CustFeeFlow>>();
                    el.Status = "SUC";
                    el.Result = custFeeFlow;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustFeeFlow({0},{1},{2},{3},{4},{5})err:" + ex.Message, custFid,startTime,endTime,type, PageSize, PageIndex));
                return string.Empty;
            }
        }
        //查询用户密码是否正确
        public string GetCustPwd(long custFid, string password)
        {
            try
            {
                string md5Pwd = null;
                md5Pwd = new com.loto.Common.ASPMD5().MD5(password);
                Model.CustInfo custInfo = new com.huigo.Framework.Model.CustInfo();
                custInfo = BLL.CustInfo.GetCustInfoByCustId(custFid);
                if (custInfo == null)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    if (md5Pwd == custInfo.CustPwd.ToLower())
                    {
                        el.Status = "SUC";
                        el.Result = new OneResult("true");
                        return com.loto.Common.SerializationHelper.GetSerializationString(el);
                    }
                    else
                    {
                        el.Status = "SUC";
                        el.Result = new OneResult("false");
                        return com.loto.Common.SerializationHelper.GetSerializationString(el);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetCustPwd({0},{1})err:" + ex.Message, custFid, password));
                return string.Empty;
            }
        }
        //修改用户密码
        public string UpdatePwd(long custFid, string pwd)
        {
            try
            {
                string md5Pwd = null;
                md5Pwd = new com.loto.Common.ASPMD5().MD5(pwd);

                int result = BLL.CustInfo.updatePwd(custFid, md5Pwd);
                if (result == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("UpdatePwd({0},{1})err:" + ex.Message, custFid, pwd));
                return string.Empty;
            }
        }
        //查询推荐产品和热销产品
        public string GetProductListIndex(int type)
        {
            try
            {
                List<Model.ProductInfo> productList = new List<com.huigo.Framework.Model.ProductInfo>();
                productList = BLL.ProductInfo.GetProductListIndex(type);
                if (productList == null || productList.Count == 0)
                {
                    return string.Empty;
                }
                else
                {
                    Response<List<Model.ProductInfo>> el = new Response<List<com.huigo.Framework.Model.ProductInfo>>();
                    el.Status = "SUC";
                    el.Result = productList;
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("GetProductListIndex({0})err:" + ex.Message, type));
                return string.Empty;
            }
        }
        //修改用户最后登录时间
        public string UpdateCustLastTime(long custId)
        {
            try
            {
                bool result = BLL.CustInfo.UpdateCustLastTime(custId);
                if (result == false)
                {
                    return string.Empty;
                }
                else
                {
                    Response<OneResult> el = new Response<OneResult>();
                    el.Status = "SUC";
                    el.Result = new OneResult(result);
                    return com.loto.Common.SerializationHelper.GetSerializationString(el);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogType.ERR, string.Format("UpdateCustLastTime({0})err:" + ex.Message, custId));
                return string.Empty;
            }
        }       
        #endregion
    }
}